home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d18 / tchk20.arc / DEMO.ARC / DEMOTIME.C < prev    next >
Text File  |  1989-01-13  |  3KB  |  84 lines

  1. /* demotime.c  -  used for testing TCHK time conversions */
  2.  
  3. #include <howard.h>
  4. #include <timehk.h>
  5.  
  6. #include <stdio.h>
  7. #include <dos.h>
  8. #include <stdlib.h>
  9. #include <string.h>
  10.  
  11. void main();
  12.  
  13. void main()
  14. {
  15.     extern int _argc;
  16.     extern char **_argv;
  17.     void *generic;
  18.     char buff[80], temp[80], temp2[80];
  19.     double dbl, dbl2;
  20.     struct time now, t, t2;
  21.     int stype, dtype;
  22.  
  23.     if (_argc<3) {
  24.         printf("DemoTime is a demonstration program of the time conversions of TCHK.\n\n");
  25.         printf("Usage:  demotime stype dtype\n\n");
  26.         printf("    demotime will convert the current time from stype format\n");
  27.         printf("    to dtype format. See TCHK.DOC for more details\n");
  28.         exit(1);
  29.     }
  30.  
  31.     stype = atoi(_argv[1]);
  32.     dtype = atoi(_argv[2]);
  33.     if (stype<1 || stype>24 || dtype<1 || dtype>24) {
  34.         printf("Invalid format (must be 1-24)\n");
  35.         exit(2);
  36.     }
  37.  
  38. /*  for this demo, I get the current time, convert it to format 21
  39.     (0HH:MM:SS:CC) via a sprintf() and then convert it to format stype
  40.     for the test of time_convert(s,d,stype,dtype).                                      */
  41.  
  42.     gettime(&now);
  43.     sprintf(buff,"%d:%02d:%02d.%02d",(int)(now.ti_hour),(int)(now.ti_min),(int)(now.ti_sec),(int)(now.ti_hund));
  44.     printf("Current time: %s\nStype %d:  ",buff,stype);
  45.     switch (stype) {
  46.         case 7: { time_convert(buff,&t,21,stype);
  47.                   printf("%d %d %d %d",t.ti_hour,t.ti_min,t.ti_sec,t.ti_hund);
  48.                   generic = (void *) &t;
  49.                   break; }
  50.         case 8:
  51.         case 9:
  52.         case 10:
  53.         case 11:
  54.         case 12: { time_convert(buff,&dbl,21,stype);
  55.                    printf("%lf",dbl);
  56.                    generic = (void *) &dbl;
  57.                    break; }
  58.         default: { time_convert(buff,temp,21,stype);
  59.                    printf("%s",temp);
  60.                    generic = (void *) temp;
  61.                    break; }
  62.     }
  63.     printf("   ->   Dtype %d:  ",dtype);
  64.     switch (dtype) {
  65.         case 7: { time_convert(generic,&t2,stype,dtype);
  66.                   printf("%d %d %d %d",t2.ti_hour,t2.ti_min,t2.ti_sec,t2.ti_hund);
  67.                   break; }
  68.         case 8:
  69.         case 9:
  70.         case 10:
  71.         case 11:
  72.         case 12: { time_convert(generic,&dbl2,stype,dtype);
  73.                    printf("%lf",dbl2);
  74.                    break; }
  75.         default: { time_convert(generic,temp2,stype,dtype);
  76.                    printf("%s",temp2);
  77.                    break; }
  78.     }
  79.     printf("\n");
  80.  
  81. /* quit */
  82.     exit(0);
  83. }
  84.